//
//  STMeController.m
//  CuiBoStore
//
//  Created by 崔博 on 16/11/28.
//  Copyright © 2016年 崔博. All rights reserved.
//

#import "STMeController.h"
#import "STMeCell.h"
#import "STItemModel.h"
#import "STMeHeaderView.h"
@interface STMeController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) STMeHeaderView *headerView;

@property (nonatomic, strong) UITableView *messageTable;
@property (nonatomic, strong) NSArray *dataArray;// 数据数组
@property (nonatomic, strong) NSMutableArray *dataList;//模型数组
@end

@implementation STMeController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGB(242, 242, 242);
    [self setUpUI];
}
#pragma mark - delegate
// tabledelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if ( [[NSUserDefaults standardUserDefaults] objectForKey:@"yes"]) {
        return self.dataList.count;
    }else
    {
        return 4;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    STMeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.itemModel = self.dataList[indexPath.row];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark - methoed
// 添加子空间
- (void)setUpUI
{
    // 注册cell
    [self.view addSubview:self.headerView];
    [self.view addSubview:self.messageTable];
    [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.left.equalTo(self.view);
        make.height.equalTo(@150);
    }];
    
    [_messageTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headerView.mas_bottom).offset(20);
        make.right.left.bottom.equalTo(self.view);
    }];
    REGISCLASSCELL(self.messageTable, STMeCell, @"cell");
}

#pragma mark - lazy
- (STMeHeaderView *)headerView
{
    if (!_headerView) {
        _headerView = [[STMeHeaderView alloc] init];
    }
    return _headerView;
}


- (UITableView *)messageTable
{
    if (!_messageTable) {
        _messageTable = [STUIKitTools tableCreat];
        _messageTable.dataSource = self;
        _messageTable.delegate = self;
        _messageTable.bounces = NO;
        _messageTable.backgroundColor = BACKGROUND_COLOR;

    }
    return _messageTable;
}
- (NSArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = @[@{@"image":@"我的界面我的收藏图标",
                         @"title":@"我的收藏"},
                       @{@"image":@"我的界面意见反馈图标",
                         @"title":@"意见反馈"},
                       @{@"image":@"我的界面关于我们图标",
                         @"title":@"关于我们"},
                       @{@"image":@"我的界面客服热线图标",
                         @"title":@"客服热线",
                         @"leftTitle":@"123434"},
                       @{@"image":@"我的界面我的优惠券图标",
                         @"title":@"我的优惠券"},
                       @{@"image":@"我的界面邀请好友图标",
                         @"title":@"邀请好友立刻赚钱"},];
    }
    return _dataArray;
}
- (NSMutableArray *)dataList
{
    if (!_dataList) {
        _dataList = [NSMutableArray array];
        for (NSDictionary *dic in self.dataArray) {
            STItemModel *m = [STItemModel mj_objectWithKeyValues:dic];
            [_dataList addObject:m];
        }
        return _dataList;
    }
    return _dataList;
}
@end
